import axios from "axios";
import { ElMessage } from 'element-plus';

const service = axios.create({
    baseURL: process.env.VUE_APP_BASE_API, 
    timeout:5000
});//创建aixos对象

// 响应拦截器
service.interceptors.response.use(
    // 第一个函数，表示请求处理成功，服务端返回的响应数据会交给response参数
    (response) => { 
        const { success, message, data } = response.data
        if (success) {
            return data;
        } else if(success == false){
            ElMessage.error(message);
            return Promise.reject(new Error(message));
        }else{
            if(response.headers['content-type'] === "application/pdf"){
                return response.data;
            }
        }
    })

export default service;